
package Componentes.RendersValidators;

import Configuraciones.Configuraciones;
import java.awt.Component;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;


public class ButtonRenderUsuarios  extends JLabel implements TableCellRenderer {

    private boolean isBordered = true;
    

    public ButtonRenderUsuarios() {
        setOpaque(true);
    }
    
    
    

    public ButtonRenderUsuarios(boolean isBordered) {
        this();
        this.isBordered = isBordered;
        
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object color, boolean isSelected, boolean hasFocus, int row, int column) {
        boolean isValid=true;
       
        String val=(String)table.getModel().getValueAt(row, 1);
        
        //usuario
        isValid=isValid && val.trim().length()>0 && val.trim().length()<16;
        if(isValid){
            Pattern p= Pattern.compile("[a-zA-Z_0-9]*");
            Matcher m= p.matcher(val);
            isValid=isValid && m.matches();
            if(!isValid) return new JButton(Configuraciones.ICONO_WARNING);
        }else
           return new JButton(Configuraciones.ICONO_INFO);
        //correo
        if(table.getModel().getValueAt(row, 3)!=null){
        val=(String)table.getModel().getValueAt(row, 3);
        
        isValid=isValid && val.trim().length()>0 && val.trim().length()<46;
        if(isValid){
            Pattern p= Pattern.compile(
                    "^[\\w\\-\\_]+(\\.[\\w\\-\\_]+)*@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}$");
            Matcher m=p.matcher(val);
            isValid=isValid && m.find();
            if(!isValid) return new JButton(Configuraciones.ICONO_WARNING);
        }else
           return new JButton(Configuraciones.ICONO_INFO);
        
        }
        
        
        return new JButton(Configuraciones.ICONO_REG_OK); 
    }


    public boolean isIsBordered() {
        return isBordered;
    }


    public void setIsBordered(boolean isBordered) {
        this.isBordered = isBordered;
    }


}


